<?PHP
	require_once("lib/user.php"); 
	require_once("lib/unit.php"); 
	require_once("lib/company.php"); 
	require_once("lib/util.php");
	require_once("lib/sql.php");
	
	$user=unserialize($_SESSION["user"]);
	$userName=$user->getUserName();
	$unitId=$user->getUnitId();
	
	$activeUnitName="NOT MAPPED";
	$activeCompanyName="NOT MAPPED";
	
	if($unitId !=null){
		
		$util=new DBUtil();
		$conn=$util->getConnection();
		
		//Validate the user
		$sql = SQLQuery::FIND_COMPANY_UNIT_DETAILS_SQL;
		$stmt = $conn->prepare( $sql);
		$stmt->bind_param('d',$unitId);
		$stmt->execute();
		
		$result = $stmt->get_result();
		if ($result->num_rows > 0) {
			while($row = $result->fetch_array()) {
				$activeCompanyName=$row["COMPANY"];
				$activeUnitName=$row["UNIT"];
			}
		}
		
	}
?>

<div id="companyunitdetail" class ="headerspan" style="margin-left:auto; margin-right:0; width:40%;">  
 <div class="reporttable" style="display:table;">
	<div style="display:table-row">
		<div style="display:table-cell;padding-left: 10px;"><font class="smallbold goldText">User</font></div><div style="display:table-cell;padding-left: 5px;"><font class="smallnormal goldText"><?PHP echo $userName; ?></font></div>
		<div style="padding-left: 10px;">|</div>
		<div style="display:table-cell;padding-left: 10px;"><font class="smallbold goldText">Company</font></div><div style="display:table-cell;padding-left: 5px;"><font class="smallnormal goldText"><div id="selectedCompanyName"><?PHP echo $activeCompanyName; ?></div></font></div>
		<div style="padding-left: 10px;">|</div>
		<div style="display:table-cell;padding-left: 10px;"><font class="smallbold goldText">Unit</font></div><div style="display:table-cell;padding-left: 5px;"><font class="smallnormal goldText"><div id="selectedUnitName"><?PHP echo $activeUnitName; ?></div></font></div>
	</div>
 </div>
</div>
